// pages/movies/movie-detail.js
let util = require("../../util/util.js")
let app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    movie: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options.movieid)
    if (options.movieid) {
      let movie_url = app.globalData.tmdb_movie_url + options.movieid + "?api_key=" + app.globalData.tmdb_api_key_v3
      util.tmdb_movie(movie_url, this.getMovieInfo)
    }

  },

  getMovieInfo: function(data) {
    console.log(data);
    let mov = {
      title: data.title, //标题
      ogtitle: data.original_title,
      vote_average: data.vote_average, //评分
      stars: util.voteToStarsArray(data.vote_average), //星星
      vote_count: data.vote_count, //评分人数
      post: app.globalData.tmdb_config.base_url + app.globalData.tmdb_config.poster_sizes + data.poster_path, //海报
      desc: data.overview, //简介
      release_date: data.release_date, //上映日期
      country: data.production_countries.map(function(val, index) {
        let c = "-" + val.name
        console.log(val.name);
        return c
      }), //国家
      vote_count: data.vote_count, //评分次数
      popularity: data.popularity, //流行度
    };
    console.log(mov);
    this.setData({
      movie: mov,
      stars: util.voteToStarsArray(mov.vote_average),
      vote_average: mov.vote_average

    })
  }
})